package cn.com.oceansoft.nos.common.util;


import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.xml.rpc.ParameterMode;

/**
 * 吉林短信接收与发送
 * webservice工具类接口
 * Created by smc on 2016/2/16.
 */
public class JlSmsWebServiceUtils {
    private static final Logger log = LoggerFactory.getLogger(JlSmsWebServiceUtils.class);
    private  static final Service service = new Service();
    /**
     *  发送短信接口
     * @param url
     * @param mobile
     * @param content
     * @param orgCd  省公安厅科通处机构代码
     * @param level  发送优先级（业务系统可灵活配置，范围[10，99]，数字越小、优先级越高，默认为99）
     */
    public static String  sendSms(String url,String mobile,String content,String orgCd,String level){
        String ret="0";
        try{
            Call call =  (Call)service.createCall();
            call.setTargetEndpointAddress(url);
            call.setOperationName("sendShortMessage");
            call.addParameter("mobile", XMLType.XSD_STRING, ParameterMode.IN);
            call.addParameter("content", XMLType.XSD_STRING, ParameterMode.IN);
            call.addParameter("orgCd", XMLType.XSD_STRING, ParameterMode.IN);
            call.addParameter("level", XMLType.XSD_STRING, ParameterMode.IN);
            call.setReturnType(XMLType.XSD_STRING);
            String result = (String)call.invoke(new Object[]{mobile,content,orgCd,level});
            Document document =  DocumentHelper.parseText(result);
            Element element = document.getRootElement();
            ret  = element.attributeValue("result");
        }catch (Exception ex){
                log.error("发送短信失败，失败信息： ",ex);
                 ret="-1";
        }
        return ret;
    }
    public  static  void receiveSms(String url){

    }

}
